<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="null">
    <meta name="keyword" content="null">
    <meta name="theme-color" content="#600090">
    <meta name="msapplication-navbutton-color" content="#600090">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="#600090">
    <link rel="shortcut icon" href="/assets/favicon.ico">
    <link rel="alternate" type="application/atom+xml" title="张小阳" href="/atom.xml">
    <link rel="stylesheet" href="https://cdn.bootcss.com/animate.css/3.5.2/animate.css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.css">
    <title>
        
        Hexo个人博客搭建笔录｜MillZhang&#39;s blog
        
    </title>

    <link rel="canonical" href="http://millzhang.github.io/2017/06/13/2017-note/13.Hexo个人博客搭建笔录/">

    <!-- Bootstrap Core CSS -->
    <link rel="stylesheet" href="/css/bootstrap.min.css">

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/css/blog-style.css">

    <!-- Pygments Github CSS -->
    <link rel="stylesheet" href="/css/syntax.css">
</head>

<!-- hack iOS CSS :active style -->
<body ontouchstart="" class="animated fadeIn">
<!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top " id="nav-top" data-ispost = "true" data-istags="false
" data-ishome = "false" >
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand animated pulse" href="/">
                <span class="brand-logo">
                    MillZhang
                </span>
            </a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <!-- Known Issue, found by Hux:
            <nav>'s height woule be hold on by its content.
            so, when navbar scale out, the <nav> will cover tags.
            also mask any touch event of tags, unfortunately.
        -->
        <!-- /.navbar-collapse -->
        <div id="huxblog_navbar">
            <div class="navbar-collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="/"><i class="fa fa-home"></i>主页</a>
                    </li>
                   <li>
                        <a href="/tags"><i class="fa fa-tags"></i>归档</a>
                    </li>
                    <li>
                        <a href="/about"><i class="fa fa-user"></i>关于</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <!-- /.container -->
</nav>
<script>
    // Drop Bootstarp low-performance Navbar
    // Use customize navbar with high-quality material design animation
    // in high-perf jank-free CSS3 implementation
//    var $body   = document.body;
    var $toggle = document.querySelector('.navbar-toggle');
    var $navbar = document.querySelector('#huxblog_navbar');
    var $collapse = document.querySelector('.navbar-collapse');

    $toggle.addEventListener('click', handleMagic)
    function handleMagic(e){
        if ($navbar.className.indexOf('in') > 0) {
        // CLOSE
            $navbar.className = " ";
            // wait until animation end.
            setTimeout(function(){
                // prevent frequently toggle
                if($navbar.className.indexOf('in') < 0) {
                    $collapse.style.height = "0px"
                }
            },400)
        }else{
        // OPEN
            $collapse.style.height = "auto"
            $navbar.className += " in";
        }
    }
</script>

<!-- Main Content -->

<!--only post-->

<header class="intro-header">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1 text-center">
                <div class="post-heading">
                    <h1>Hexo个人博客搭建笔录</h1>
                    
                    <span class="meta">
                         作者 MillZhang
                        <span>
                          日期 2017-06-13
                         </span>
                    </span>
                    <div class="tags text-center">
                        
                        <a class="tag" href="/tags/#node"
                           title="node">node</a>
                        
                        <a class="tag" href="/tags/#hexo"
                           title="hexo">hexo</a>
                        
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="post-title-haojen">
        <span>
            Hexo个人博客搭建笔录
        </span>
    </div>
    <div class="post-header-image">
        
            <img src="http://oritfw5nq.bkt.clouddn.com/wall-303.jpg?imageView2/0/format/jpg/interlace/1/q/85|watermark/2/text/QnkgTWlsbHpoYW5n/font/5b6u6L2v6ZuF6buR/fontsize/480/fill/I0ZERkRGRA==/dissolve/56/gravity/SouthEast/dx/10/dy/10|imageslim">
         
    </div>
</header>

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">
            <!-- Post Container -->
            <div class="col-lg-8 col-lg-offset-1 col-sm-9 post-container">
                <h3 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h3><ul>
<li><a href="https://hexo.io/zh-cn/docs/" target="_blank" rel="external">hexo官方文档</a></li>
<li><a href="http://baixin.io/2015/08/HEXO%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/" target="_blank" rel="external">博客</a></li>
</ul>
<h3 id="环境装备"><a href="#环境装备" class="headerlink" title="环境装备"></a>环境装备</h3><ol>
<li>nodejs(最后大于6.0);</li>
<li><code>hexo</code>,通过<code>npm install hexo -g</code>安装;</li>
<li>github仓库(username.github.io)</li>
</ol>
<a id="more"></a>
<h3 id="常用命令"><a href="#常用命令" class="headerlink" title="常用命令"></a>常用命令</h3><ul>
<li><code>hexo init</code>创建文件夹;</li>
<li><code>hexo clean</code>清除文件;</li>
<li><code>hexo g/hexo generate</code>生成静态文件;</li>
<li><code>hexo d/hexo deploy</code>远程发布 ;</li>
<li><code>hexo server</code>启动本地服务</li>
</ul>
<h3 id="hexo与github仓库的关联提交"><a href="#hexo与github仓库的关联提交" class="headerlink" title="hexo与github仓库的关联提交"></a>hexo与github仓库的关联提交</h3><p>在博客根目录下的<code>_config.yml</code>的文件中,修改如下代码:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">deploy:</div><div class="line">    type: git</div><div class="line">    repo: https://github.com/MillZhang/millzhang.github.io.git #远程git仓库</div><div class="line">    branch: master</div></pre></td></tr></table></figure>
<h3 id="主题Themes"><a href="#主题Themes" class="headerlink" title="主题Themes"></a>主题Themes</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia</div></pre></td></tr></table></figure>
<p>该主题需安装插件,生成所有文章的目录</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="comment">//仅支持node&gt;6.0</span></div><div class="line">npm i hexo-generator-json-content --save</div></pre></td></tr></table></figure>
<p>安装完成后需要在根目录下的<code>_config.yml</code>中添加如下的配置:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line"># 所有文章目录</div><div class="line">jsonContent:</div><div class="line">    meta: false</div><div class="line">    pages: false</div><div class="line">    posts:</div><div class="line">      title: true</div><div class="line">      date: true</div><div class="line">      path: true</div><div class="line">      text: false</div><div class="line">      raw: false</div><div class="line">      content: false</div><div class="line">      slug: false</div><div class="line">      updated: false</div><div class="line">      comments: false</div><div class="line">      link: false</div><div class="line">      permalink: false</div><div class="line">      excerpt: false</div><div class="line">      categories: false</div><div class="line">      tags: true</div></pre></td></tr></table></figure>
<h3 id="一些小技巧"><a href="#一些小技巧" class="headerlink" title="一些小技巧"></a>一些小技巧</h3><ul>
<li>让文章只显示一部分,只需要在文章中添加<code>&lt;!--more--&gt;</code>,<code>&lt;!--more--&gt;</code>后面的内容就不显示了;</li>
<li>给文章分类(tags),需要在稳重添加<code>tags:[node,javascript]</code></li>
</ul>
<h3 id="插件"><a href="#插件" class="headerlink" title="插件"></a>插件</h3><p>1.使用git同步到git仓库</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install hexo-deployer-git --save</div></pre></td></tr></table></figure>
<p>2.生成易于搜索引擎搜素的网站地图</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install hexo-generator-sitemap --save</div></pre></td></tr></table></figure>
<p>3.生成rss订阅文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install hexo-generator-feed --save</div></pre></td></tr></table></figure>
<h3 id="hexo免密提交"><a href="#hexo免密提交" class="headerlink" title="hexo免密提交"></a>hexo免密提交</h3><p>1.输入指令，进入.ssh文件夹<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">cd ~/.ssh/</div></pre></td></tr></table></figure></p>
<p>如无文件夹,可手动创建<code>.ssh</code>文件夹</p>
<p>2.配置全局的name和email，这里是的你github或者bitbucket的name和email</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">git config --global user.name &quot;millzhang&quot;  </div><div class="line">  </div><div class="line">git config --global user.email &quot;876753183@qq.com&quot;</div></pre></td></tr></table></figure>
<p>3.生成key</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ssh-keygen -t rsa -C &quot;876753183@qq.com&quot;</div></pre></td></tr></table></figure>
<p>连续按三次回车，这里设置的密码就为空了，并且创建了key。</p>
<p>4.拷贝<code>id_rsa.pub</code>文件中的<code>key</code>,在<code>millzhang.github.io</code>的<code>Settings</code>中找到<code>Deploy Key</code>粘贴.</p>
<p>5.在博客根目录下的<code>_config.yml</code>中修改</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">deploy:</div><div class="line">    type: git</div><div class="line">    repo: git@github.com:MillZhang/millzhang.github.io.git #修改</div><div class="line">    branch: master</div></pre></td></tr></table></figure>
<p>6.使用<code>hexo d</code>就可以免密提交啦!</p>
<h3 id="个人域名的绑定"><a href="#个人域名的绑定" class="headerlink" title="个人域名的绑定"></a>个人域名的绑定</h3><p>1.在腾讯云申请域名<code>zy1991.cn</code>,进行实名认证.<br>2.在腾讯云进行域名解析,如下图操作:<br><img src="http://oritfw5nq.bkt.clouddn.com/QQ%E6%88%AA%E5%9B%BE20170615141211.png" alt="操作示意图"><br>3.进入博客根目录下的<code>source</code>文件夹,新建<code>CNAME</code>,<code>CNAME</code>中输入域名<code>zy1991.cn</code>;<br>4.<code>hexo clean &amp; hexo g &amp; hexo d</code>即可访问自定义域名<code>zy1991.cn</code>下的博客啦;</p>
<p>[注]: <a href="https://www.qcloud.com/product/tools?from=cns" target="_blank" rel="external">检测工具</a> 可查看域名的解析状态</p>
<h3 id="网易云跟帖"><a href="#网易云跟帖" class="headerlink" title="网易云跟帖"></a>网易云跟帖</h3><p>这部分比较简答,注册网易云跟帖账号,按步骤绑定项目,直接拷贝代码至主题下的<code>post.ejs</code></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"comment"</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"cloud-tie-wrapper"</span> <span class="attr">class</span>=<span class="string">"cloud-tie-wrapper"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></div></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">&lt;!-- 网易云跟帖--&gt;</div><div class="line"><span class="xml"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"https://img1.cache.netease.com/f2e/tie/yun/sdk/loader.js"</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span></div><div class="line">&lt;script&gt;</div><div class="line"><span class="keyword">var</span> cloudTieConfig = &#123;</div><div class="line">  <span class="attr">url</span>: <span class="built_in">document</span>.location.href, </div><div class="line">  <span class="attr">sourceId</span>: <span class="string">""</span>,</div><div class="line">  <span class="attr">productKey</span>: <span class="string">"40a8ee22b6084862a8907e6902e525fa"</span>,</div><div class="line">  <span class="attr">target</span>: <span class="string">"cloud-tie-wrapper"</span></div><div class="line">&#125;;</div><div class="line"><span class="keyword">var</span> yunManualLoad = <span class="literal">true</span>;</div><div class="line">Tie.loader(<span class="string">"aHR0cHM6Ly9hcGkuZ2VudGllLjE2My5jb20vcGMvbGl2ZXNjcmlwdC5odG1s"</span>, <span class="literal">true</span>);</div><div class="line"><span class="xml"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span></div></pre></td></tr></table></figure>
<h3 id="网易云音乐"><a href="#网易云音乐" class="headerlink" title="网易云音乐"></a>网易云音乐</h3><p>这部分做了些自定义,目的是想让每篇文章可控制不同的音乐,并可限制是否自动播放,功能比较简单,直接上代码,同样是在<code>post.ejs</code>中:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">&lt;!-- 网易云音乐--&gt;</div><div class="line">&lt;% var musicId=page.music ? page.music : config.defaultMusic,</div><div class="line">       isAuto = page.musicAuto ? page.musicAuto : config.defaultMusicAuto;</div><div class="line">    if(musicId == undefined)&#123; musicId = 586299&#125;;</div><div class="line">    var musicLink = &apos;//music.163.com/outchain/player?type=2&amp;id=&apos;+musicId+&apos;&amp;auto=&apos;+Number(isAuto)+&apos;&amp;height=66&apos;;</div><div class="line"> %&gt;</div><div class="line">&lt;iframe class=&quot;cloud-music&quot; frameborder=&quot;no&quot; border=&quot;0&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; width=330 height=86 </div><div class="line">    src=&quot;&lt;%= musicLink %&gt;&quot;&gt;</div><div class="line">&lt;/iframe&gt;</div></pre></td></tr></table></figure>
<p>在<code>_config.yml</code>中添加了如下的配置:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">defaultMusic: 586299 //网易云音乐外链播放id</div><div class="line">defaultMusicAuto: false //默认不开启自动播放</div></pre></td></tr></table></figure>

                <hr>
                <ul class="pager">
                    
                    <li class="previous">
                        <a href="/2017/06/14/2017-note/14.页面回到顶部滚动按钮实现/" data-toggle="tooltip" data-placement="top"
                           title="页面回到顶部滚动按钮平滑滚动">&larr; 上一页</a>
                    </li>
                    
                    
                    <li class="next">
                        <a href="/2017/06/13/2017-note/12.node笔录/" data-toggle="tooltip" data-placement="top"
                           title="node笔录">下一页 &rarr;</a>
                    </li>
                    
                </ul>
                <div class="comment">
                    <div id="cloud-tie-wrapper" class="cloud-tie-wrapper"></div>
                </div>
            </div>
            <div class="hidden-xs col-sm-3 toc-col">
                <div class="toc-wrap">
                    <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#参考"><span class="toc-text">参考</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#环境装备"><span class="toc-text">环境装备</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#常用命令"><span class="toc-text">常用命令</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#hexo与github仓库的关联提交"><span class="toc-text">hexo与github仓库的关联提交</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#主题Themes"><span class="toc-text">主题Themes</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#一些小技巧"><span class="toc-text">一些小技巧</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#插件"><span class="toc-text">插件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#hexo免密提交"><span class="toc-text">hexo免密提交</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#个人域名的绑定"><span class="toc-text">个人域名的绑定</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#网易云跟帖"><span class="toc-text">网易云跟帖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#网易云音乐"><span class="toc-text">网易云音乐</span></a></li></ol>
                </div>
            </div>
        </div>

        <div class="row">
            <!-- Sidebar Container -->

            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                sidebar-container">

                <!-- Featured Tags -->
                

                <!-- Friends Blog -->
                
            </div>
        </div>

    </div>
</article>
<!-- 网易云音乐-->

<iframe class="cloud-music" frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 
    src="//music.163.com/outchain/player?type=2&amp;id=18803411&amp;auto=0&amp;height=66">
</iframe>
<!-- 网易云跟帖-->
<script src="https://img1.cache.netease.com/f2e/tie/yun/sdk/loader.js"></script>
<script>
var cloudTieConfig = {
  url: document.location.href, 
  sourceId: "",
  productKey: "40a8ee22b6084862a8907e6902e525fa",
  target: "cloud-tie-wrapper"
};
var yunManualLoad = true;
Tie.loader("aHR0cHM6Ly9hcGkuZ2VudGllLjE2My5jb20vcGMvbGl2ZXNjcmlwdC5odG1s", true);
</script>

<!-- Footer -->
<!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1 text-center">
                <p class="copyright text-muted">
                    Copyright &copy; MillZhang 2017
                    <br>
                </p>
            </div>
        </div>
    </div>
</footer>

<!-- jQuery -->
<script src="/js/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="/js/bootstrap.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="/js/blog.js"></script>

<!-- async load function -->
<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>

<!-- jquery.tagcloud.js -->
<script>
    // only load tagcloud.js in tag.html
    if($('#tag_cloud').length !== 0){
        async("http://oritfw5nq.bkt.clouddn.com/jquery.tagcloud.js",function(){
            $.fn.tagcloud.defaults = {
                //size: {start: 1, end: 1, unit: 'em'},
                color: {start: '#bbbbee', end: '#0085a1'},
            };
            $('#tag_cloud a').tagcloud();
        })
    }
</script>

<!--fastClick.js -->
<script>
    async("//cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js", function(){
        var $nav = document.querySelector("nav");
        if($nav) FastClick.attach($nav);
    })
</script>



<!--wechat title img-->
<img class="wechat-title-img" src="http://oritfw5nq.bkt.clouddn.com/avatar.jpg?imageslim">
<a id="backtop" class="border-bottom" href="javascript:;">回顶部</a>
<script type="application/javascript">
var docOuter = document.body.scrollTop ? document.body : document.documentElement;
var backToTop = function(rate) {
  var doc = document.body.scrollTop ? document.body : document.documentElement;
  var scrollTop = doc.scrollTop;
  var top = function() {
    scrollTop = scrollTop + (0 - scrollTop) / (rate || 2);
    if (scrollTop < 1) {
      doc.scrollTop = 0;
      return;
    }
    doc.scrollTop = scrollTop;
    // 动画gogogo!
    requestAnimationFrame(top);
  };
  top();
};
var topBtn = document.getElementById('backtop'),
    docTop = docOuter.scrollTop;
if(docTop>=300){
  topBtn.style.opacity = 1;
}

topBtn.onclick = function() {
  backToTop(12)
}
window.onscroll = function(e) {
  var doc = document.body.scrollTop ? document.body : document.documentElement;
  var scrollTop = doc.scrollTop;
  if (scrollTop >= 300) {
    topBtn.style.opacity = 1;
  } else {
    topBtn.style.opacity = 0;
  }
}
</script>
</body>

</html>
